<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="servlets.*"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div class="page-header">
	<h2 class="page-title">Nowy news</h2>
</div>

<br>
<br>
<form action="../AddNews" method="POST" name='formularz'>
					
		<table>
			
			<tr>
				<td>Temat newsa:</td>
				<td><input type="text" id="subject" name="subject" style="width: 80%" required></input></td>
			</tr>
			<tr>
				<td>Treśc newsa:</td>
				<td><textarea id="content" name="content" cols="50" rows="10" style="width: 80%" required> </textarea>
				</td>
			</tr>
			<tr>
				<td><input type="submit" class="mainBtn" value="Dodaj newsa" /></td>
			</tr>
		</table>
	</form>




<div class="page-header">
	<h2 class="page-title">Newsy</h2>
</div>
<div id="content">
<br />




<%
						SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
						NewsMethods nm = new NewsMethods();
						List<News> all = nm.listAllNews(sessionFactory, s);
					%> 
			<table>
<%
		if (all.size() > 0) {
	for (News n : all) {
		int news_id = n.getNews_id();
		String subject  = n.getSubject();
		String content = n.getContent();
		%>
<tr>
<td>
		<div class="col-md-4 col-sm-6" style="width: 666px;">
											<div class="team-member">
												 <div class="member-thumb">
												<!--	<img src="images/team3.jpg" alt=""> -->
												</div>
												<div class="member-infos">
													<h4 class="member-name">
													<%out.println("<a class=\"news\" id=\""+ news_id + "\" href=\"#\">" + subject + "</a>"); %></h4>
													<span class="member-role">
													<%out.println(content); %>
													</span>
												</div>
											</div>
										</div>
									
									</td>
									</tr>
									<tr> <td><br /></td></tr>
								
		<%
		}
	%>
	
	</table>
	<%
		}
		s.getTransaction().commit();
		%>

</div>		
		